// pages/cues/topic/index.ts
Page({

  /**
   * 页面的初始数据
   */
  data: {
    access: {} as any,// 当前用户权限
    currentUser: {},//当前用户完整信息
    navBarHeight: 0,//导航栏高度
    tabKeyValue: '',//选择的tab
    tabList: [],//线索征集tab
    mode: 0,//分页类型
  },
  /**
  * 页面上拉触底事件的处理函数
  */
  onReachBottom() {
    switch (this.data.mode) {
      case 1:
        this.tableTopicRender.scrollBottom();
        break;
      case 2:
        this.tableTopicMedia.scrollBottom();
        break;
      case 3:
        this.tableTopicManage.scrollBottom();
        break;
      case 4:
        this.tableTopicAssist.scrollBottom();
        break;
      case 5:
        this.tableSubmit.scrollBottom();
        break;
    }
  },
  //选题征集的tab改变
  onTabsChange(e) {
    this.setData({ tabKeyValue: e.detail.value, mode: e.detail.value })
    this.onReady()
  },
  //回到顶部
  onToTop(e) {
  },
  //创建选题计划
  handleCreateTopic() {
    wx.navigateTo({
      url: '/pages/cues/topic/create/index?mode=' + this.data.mode
    })
  },
  //获取tab值
  getTabList() {
    const access = this.data.access
    let tabList = []
    if (access.cuesTopicConfigManage) {
      tabList = [
        {
          tab: '选题计划',
          key: 'TableTopicRender',
          mode: 1
        },
        {
          tab: '选题审批',
          key: 'TableTopicManage',
          mode: 3
        },
        {
          tab: '选题线索',
          key: 'TableSubmit',
          mode: 5
        },
      ]
    } else if (access.cuesTopicConfigManage || access.cuesTopicConfigNeedMedia) {
      tabList = [
        {
          tab: '我的选题计划',
          key: 'TableTopicMedia',
          mode: 2
        },
        {
          tab: access.线索征集x配置x部门需求者 ? '联动选题征集' : '协作选题征集',
          key: 'TableTopicAssist',
          mode: 4
        },
        {
          tab: '选题线索',
          key: 'TableSubmit',
          mode: 5
        },
      ]
    } else if (access.cuesTopicConfigRender) {
      tabList = [
        {
          tab: '选题征集',
          key: 'TableTopicRender',
          mode: 1
        },
        {
          tab: '我的选题征集',
          key: 'TableTopicMedia',
          mode: 2
        },
        {
          tab: '联动选题征集',
          key: 'TableTopicAssist',
          mode: 4
        },
        {
          tab: '选题线索',
          key: 'TableSubmit',
          mode: 5
        },
      ]
    }
    this.setData({
      tabList,
      tabKeyValue: tabList[0].mode,
      mode: tabList[0].mode
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options: { mode: any }) {
    const { globalData: { access, navBarHeight, currentUser } } = getApp();

    this.setData({
      access: access,
      navBarHeight,
      currentUser
    })
    this.getTabList();
    if (options.mode !== null && options.mode !== undefined && options.mode !== '') {
      this.setData({
        mode: options.mode,
        tabKeyValue: options.mode
      })
    } else {
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.tableTopicRender = this.selectComponent("#tableTopicRender")
    this.tableTopicManage = this.selectComponent("#tableTopicManage")
    this.tableTopicMedia = this.selectComponent("#tableTopicMedia")
    this.tableSubmit = this.selectComponent("#tableSubmit")
    this.tableTopicAssist = this.selectComponent("#tableTopicAssist")

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})